package com.neuedu.javase.api;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-09-28 16:21
 * 描述 :
 */
public class MyStringBuffer {
    public static void main(String[] args) {
//        StringBuffer stringBuffer1 = new StringBuffer();
        StringBuffer stringBuffer2 = new StringBuffer(32);
        StringBuffer stringBuffer3 = new StringBuffer("abc");

        System.out.println("stringBuffer2.capacity() = " + stringBuffer2.capacity());// 32
        System.out.println("stringBuffer3.capacity() = " + stringBuffer3.capacity());// 19
        System.out.println("stringBuffer3.length() = " + stringBuffer3.length()); // 3

        stringBuffer3.append("def");
        System.out.println("stringBuffer3.capacity() = " + stringBuffer3.capacity());// 19
        System.out.println("stringBuffer3.length() = " + stringBuffer3.length()); //6


        //StringBuffer 是一个可变长的对象
        stringBuffer3.append("qqq").append("QWERTYUIOP------------");
        System.out.println("stringBuffer3.capacity() = " + stringBuffer3.capacity());// ?
        System.out.println("stringBuffer3.length() = " + stringBuffer3.length()); //19

        StringBuffer sbuffer1 = new StringBuffer("0123456");


        System.out.println("sbuffer1 = " + sbuffer1);
        sbuffer1.insert(1,"new");

        System.out.println("sbuffer1.insert(1,\"new\") " );
        System.out.println("sbuffer1 = " + sbuffer1);


        int start = sbuffer1.indexOf("new");
        int end = start + "new".length() ;
        sbuffer1.delete(start,end);
        System.out.println("sbuffer1 = " + sbuffer1);

        System.out.println("sbuffer1.deleteCharAt(3) = " + sbuffer1.deleteCharAt(3));
        System.out.println("sbuffer1.reverse() = " + sbuffer1.reverse());

        StringBuffer sBufferE1 = new StringBuffer("abcdef");
        StringBuffer sBufferE2 = new StringBuffer("abcdef");
        System.out.println("(sBufferE1 == sBufferE2) = " + (sBufferE1 == sBufferE2));

        //StringBuffer 没有重写Equals
        System.out.println(" (sBufferE1.equals(sBufferE2)) = " + (sBufferE1.equals(sBufferE2)));

        //equals
        System.out.println("sBufferE1.toString().equals(sBufferE2.toString()) = " + sBufferE1.toString().equals(sBufferE2.toString()));



        String str1 = "abc";
        String str2 = new String("abc");
        str2 = null;  //  null.equals 空指针
        System.out.println("str2.equals(str1) = " + str2.equals(str1));
        System.out.println("str1.equals(str2) = " + str1.equals(str2));  //√


         // "abc".equals(new String("abc"));

    }
}
